package com.sumer.psychology.sharing.domain.model;

import com.sumer.psychology.sharing.application.command.CreateSharedResourceCommand;
import org.apache.commons.collections.CollectionUtils;

/**
 * 共享资源工厂
 * <p/>
 * User: zhenguang.zhu
 * Date: 2014/9/11
 * Time: 16:10
 */
public class SharedResourceFactory {
    private static SharedResourceFactory sharedResourceFactory = new SharedResourceFactory();

    private SharedResourceFactory() {
    }

    public static SharedResourceFactory instance() {
        return sharedResourceFactory;
    }

    public SharedResource create(CreateSharedResourceCommand createSharedResourceCommand,
                                        SharedResourceRepository sharedResourceRepository) {
        SharedResource aSharedResource = new SharedResource(
                sharedResourceRepository.nextIdentity(),
                createSharedResourceCommand.topic(),
                createSharedResourceCommand.author(),
                createSharedResourceCommand.sharedFiles());

        if (CollectionUtils.isNotEmpty(createSharedResourceCommand.tags())) {
            aSharedResource.replaceTags(createSharedResourceCommand.tags());
        }

        return aSharedResource;
    }
}
